using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using QLNS.Data;
using QLNS.Object;
using System.Windows.Forms;

namespace QLNS.Control
{
    class BangLuongCtrl
    {
        BangLuong_db data = new BangLuong_db();

        BindingSource bs = new BindingSource();
        
        public void HienthiBangLuongDataGridview(DataGridView dg, BindingNavigator bn)
        {
            BindingSource bs = new BindingSource();
            DataTable tbl = data.DanhSachBangLuong();
            bs.DataSource = tbl;
            bn.BindingSource = bs;
            dg.DataSource = bs;

        }

        public void HienthiBangLuongDataGridview(System.Windows.Forms.DataGridView dg, System.Windows.Forms.BindingNavigator bn,
            DateTimePicker dtpThang, ComboBox cmbNhanVien, ComboBox cmbPhongBan, TextBox txtGioCong, TextBox txtDonGia, TextBox txtNgayCong, TextBox txtHSTN, ComboBox cmbBacLuong, ComboBox cmbNgach, TextBox txtHeSoLuong, TextBox txtBHXH, TextBox txtBHYT, TextBox txtBHTN, TextBox txtTamUng, TextBox txtLuong)
        {
            System.Windows.Forms.BindingSource bs = new System.Windows.Forms.BindingSource();
            bs.DataSource = data.DanhSachBangLuong();

            dtpThang.DataBindings.Clear();
            dtpThang.DataBindings.Add("Value", bs, "Thang");

            cmbNhanVien.DataBindings.Clear();
            cmbNhanVien.DataBindings.Add("SelectedValue", bs, "ID");

            cmbPhongBan.DataBindings.Clear();
            cmbPhongBan.DataBindings.Add("SelectedValue", bs, "PhongBan");

            txtGioCong .DataBindings.Clear();
            txtGioCong.DataBindings.Add("Text", bs, "GioCong");

            txtDonGia.DataBindings.Clear();
            txtDonGia.DataBindings.Add("Text", bs, "DonGia");

            txtNgayCong.DataBindings.Clear();
            txtNgayCong.DataBindings.Add("Text", bs, "NgayCong");
     
            txtHSTN.DataBindings.Clear();
            txtHSTN.DataBindings.Add("Text", bs, "HeSoTrachNhiem");

            txtHeSoLuong.DataBindings.Clear();
            txtHeSoLuong.DataBindings.Add("Text", bs, "HeSoLuong");

            cmbNgach.DataBindings.Clear();
            cmbNgach.DataBindings.Add("SelectedValue", bs, "Ngach");
            
            cmbBacLuong.DataBindings.Clear();
            cmbBacLuong.DataBindings.Add("SelectedValue", bs, "BacLuong");

            txtBHXH.DataBindings.Clear();
            txtBHXH.DataBindings.Add("Text", bs, "BaoHiemXaHoi");

            txtBHYT.DataBindings.Clear();
            txtBHYT.DataBindings.Add("Text", bs, "BaoHiemYTe");

            txtBHTN.DataBindings.Clear();
            txtBHTN.DataBindings.Add("Text", bs, "BaoHiemThatNghiep");

            txtTamUng.DataBindings.Clear();
            txtTamUng.DataBindings.Add("Text", bs, "TamUng");

            txtLuong.DataBindings.Clear();
            txtLuong.DataBindings.Add("Text", bs, "TongLuong");


            bn.BindingSource = bs;
            dg.DataSource = bs;
        }

        /*public IList<BangLuong_obj> LayDanhSachBangLuong()
        {
            DataTable tbl = data.DanhSachBangLuong();
            IList<BangLuong_obj> ds = new List<BangLuong_obj>();

            foreach (DataRow row in tbl.Rows)
            {
                BangLuong_obj bangluong = new BangLuong_obj();
                bangluong.Thang = Convert.ToDateTime(row["Thang"]);
                bangluong.NhanVien_ID = Convert.ToString(row["NHANVIEN_ID"]);
                bangluong.Ho = Convert.ToString(row["Ho"]);
                bangluong.TenLot = Convert.ToString(row["TenLot"]);
                bangluong.Ten = Convert.ToString(row["Ten"]);
                bangluong.PhongBan = Convert.ToString(row["PhongBan"]);
                bangluong.GioCong = Convert.ToDouble(row["GioCong"]);
                bangluong.DonGia = Convert.ToDouble(row["DonGia"]);
                bangluong.GioCong = Convert.ToDouble(row["NgayCong"]);
                bangluong.DonGia = Convert.ToDouble(row["HeSoLuong"]);
                bangluong.HeSoTrachNhiem = Convert.ToDouble(row["HeSoTrachNhiem"]);
                bangluong.BacLuong = Convert.ToDouble(row["BacLuong"]);
                bangluong.TongPhuCap = Convert.ToDouble(row["TongPhuCap"]);
                bangluong.TongGiamTru = Convert.ToDouble(row["TongGiamTru"]);
                bangluong.TongLuong = Convert.ToDouble(row["TongLuong"]);
                ds.Add(bangluong);
            }
            return ds;
        }*/
        public string TimMa(String ma)
        {
            data.TimMa(ma);
            if (data != null)
                return ma;
            return null;
        }

        public string TimTen(string ten)
        {
            data.TimTen(ten);
            if (data != null)
                return ten;
            return null;
        }

        public DataRow NewRow()
        {
            return data.NewRow();
        }
        public void Add(DataRow row)
        {
            data.Add(row);
        }
        public bool Save()
        {
            return data.Save();
        }
        public void Update()
        {
            bs.MoveNext();
            data.Save();
        }
    }
}
